const Controller = require('egg').Controller

class NoticeController extends Controller {
  // 发送通知
  async create() {
    const { ctx } = this;
    const { message, receiverId } = ctx.request.body;

    // 获取当前管理员ID，假设是登录的用户
    const senderId = ctx.user.id;

    // 保存通知
    const result = await ctx.service.notice.createNotice(senderId, receiverId, message);

    ctx.body = {
      success: true,
      message: '发送成功',
      data: result,
    };
  }
  // 获取通知列表
  async list() {
    const { ctx } = this;
    console.log(ctx.user.id)
    const userId = ctx.user.id;

    // 获取该用户的通知
    const notice = await ctx.service.notice.getNotice(userId);

    ctx.body = {
      code: 200,
      message: '请求成功',
      data: notice,
    };
  }
  // 更新通知状态
  async updateStatus() {
    const { ctx } = this;
    const { noticeId, status } = ctx.request.body;

    // 更新通知状态
    const result = await ctx.service.notice.updateStatus(noticeId, status);

    ctx.body = {
      success: true,
      message: '更新成功',
      data: result,
    };
  }
}

module.exports = NoticeController;
